package com.leetcode.p0;

/**
 * 时间 复杂度 n^2
 */
public class Test45 {

    public int jump(int[] nums) {
        if (nums.length <= 1) {
            return 0;
        }

        int step = 0;
        int position = nums.length - 1;

        while (position > 0) {
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] + i >= position) {
                    step++;
                    position = i;
                    break;
                }
            }
        }

        return step;
    }

    public static void main(String[] args) {
        Test45 test = new Test45();
        int result = test.jump(new int[]{7, 0, 30, 6, 9, 6, 1, 7, 9, 0, 1, 2, 9, 0, 3, 1});
        System.out.println(result);
    }

}
